package com.jsyh.maidu.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RatingBar;
import android.widget.TextView;

import com.jsyh.maidu.R;
import com.jsyh.maidu.model.CommentModel;

import java.util.List;

/**
 * Created by ZHY_9 on 2017/7/19.
 */

public class CommentListAdapter extends RecyclerView.Adapter<CommentListAdapter.CommentHolder> {

    Context context;
    List<CommentModel.CommentInfo> data;

    public CommentListAdapter(Context context, List<CommentModel.CommentInfo> data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public CommentHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.comment_item, null);
        CommentHolder holder = new CommentHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(CommentHolder holder, int position) {
        holder.name.setText(data.get(position).getUser_name());
        holder.score.setRating(Float.valueOf(data.get(position).getComment_rank()));
        holder.content.setText(data.get(position).getContent());
        holder.time.setText(data.get(position).getComment_time());
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    class CommentHolder extends RecyclerView.ViewHolder{


        TextView name;
        RatingBar score;
        TextView content;
        TextView time;
        TextView reserveContent;

        public CommentHolder(View itemView) {
            super(itemView);
            name = (TextView) itemView.findViewById(R.id.tv_comment_username);
            score = (RatingBar) itemView.findViewById(R.id.rb_start);
            content = (TextView) itemView.findViewById(R.id.tv_conment_contexnt);
            time = (TextView) itemView.findViewById(R.id.tv_comment_time);
            reserveContent = (TextView) itemView.findViewById(R.id.tv_comment_reserve);

        }
    }
}
